#include <iostream>
#include <string>
#include "../comm/httplib.h"
#include "./oj_control.hpp"
#include "./oj_model.hpp"
using namespace httplib;
using namespace control;
int main()
{
    Server svr;
    Control ctrl;
    svr.Get("/all_questions", [&ctrl](const Request &req, Response &resp)
            { 
                std::string html;
                ctrl.AllQuestions(&html);
                resp.set_content(html, "text/html; charset=utf-8"); 
            });
    svr.Get(R"(/question/(\d+))",[&ctrl](const Request &req, Response &resp)
            {
                std::string number = req.matches[1]; 
                std::string html;
                ctrl.OneQuestion(&html,number);
                resp.set_content(html, "text/html; charset=utf-8");
            });
    svr.Post(R"(/judge/(\d+))",[&ctrl](const Request &req, Response &resp)
            {
                std::string number = req.matches[1];
                std::string out_json;
                ctrl.Judge(number,req.body,&out_json);
                resp.set_content(out_json, "text/json; charset=utf-8");
            });
    svr.set_base_dir("./wwwroot");
    svr.listen("0.0.0.0", 8080);
    return 0;
}